<?php
session_start();
header("Content-type: image/PNG");
$img_w = 60;
$img_h = 18;
$length = 5;



$l = pow(10, $length);
$string = (string) rand($l / 10, $l - 1);
$_SESSION['brk_verifycode']=$string;
$bg = imagecreatefromjpeg("../data/verify/verify.bg.jpg");
$bg_src_x = rand(0, imagesx($bg) - $img_w);
$bg_src_y = rand(0, imagesy($bg) - $img_h);

$im = imagecreatetruecolor($img_w, $img_h);
imagecopy($im, $bg, 0, 0, $bg_src_x, $bg_src_y, $img_w, $img_h);
ImageDestroy($bg);

$RGB = rand(120, 150);
imagefilter($im, IMG_FILTER_COLORIZE, $RGB, $RGB, $RGB);
$RGB = 255 - $RGB;

$ww = $img_w / $length;
for ($i = 0; $i < $length; $i++) {
    $font = rand(3, 5);
    $x = rand($i * $ww, $i * $ww - imagefontwidth($font) + 10);
    $y = rand(0, $img_h - imagefontheight($font));
    $textcolor = imagecolorallocate($im, $RGB, $RGB, $RGB);
    imagestring($im, $font, $x, $y, $string{$i}, $textcolor);
}

ImagePNG($im);
ImageDestroy($im);
?>